﻿#include "ssBaseDefine.h"
#include "./tools/ssProcessInfo.h"
#include "./log/ssLog.h"

#ifdef SS_NEW_OPERATOR
void print_new_log(size_t size, const char *file, int line)
{
	static StarSeeker::ssLog log(1, ("./"+StarSeeker::ssProcess::instance()->m_name + "_memlog/").c_str());
	log.PrintFileEx("%u memory allocate at %s:%d", size, file, line);
}
void* operator new[](size_t size, const char *file, int line)
{
	//std::cout << size << "memory allocate at " << file << " line " << line << std::endl;
	void *p = ::operator new(size);// operator new (size,std::nothrow)
	print_new_log(size, file, line);
	return p;
}
void* operator new(size_t size, const char *file, int line)
{
	//std::cout << size << " memory allocate at " << file << " line " << line << std::endl;
	void *p = ::operator new(size);
	print_new_log(size, file, line);
	return p;
}
void operator delete(void* pdead, const char *file, int line)
{
	if (pdead)
		::operator delete(pdead);
}
//void operator delete[](void* pdead)
//{
//	if (pdead)
//		::operator delete(pdead);
//}
//void operator delete[](void* pdead, size_t size)
//{
//	if (pdead)
//		::operator delete(pdead);
//}
#endif

namespace StarSeeker
{
	bool CheckVariableLength()
	{
		if (cg_i32_size == 4 && cg_u32_size == 4 && cg_i8_size == 1 && cg_u8_size == 1
			&& cg_i16_size == 2 && cg_u16_size == 2 && cg_i64_size == 8 && cg_u64_size == 8
			&& cg_f32_size == 4 && cg_f64_size == 8)
		{
#ifdef SS_USE_32BIT
			if (cg_point_size == 4 && cg_lint_size == 4 && cg_ulint_size == 4 && sizeof(ST32_u) == 4
				&& sizeof(ST64_u) == 8)
#else
			if (cg_point_size == 8 && cg_lint_size == 8 && cg_ulint_size == 8 && sizeof(ST32_u) == 4
				&& sizeof(ST64_u) == 8)
#endif
				return true;
		}
		return false;
	}
}
